#

| Chapter 27 Searching Through Files |

## 27.17 Finding a Character in a Column

Here's an idea for finding lines that have a given character in a column. Use the following simple awk (33.11) command:

>     % awk 'substr($0,n,1) == "c"' filename

where c is the character you're searching for, and n is the column you care about.

Where would you do this? If you're processing a file with very strict formatting, this might be useful; for example, you might have a telephone list with a `#` in column 2 for "audio" telephone numbers, `$` for dial-up modems, and `%` for fax machines. A script for looking up phone numbers might use an awk command like this to prevent you from mistakenly talking to a fax machine.

If your data has any TAB characters, the columns might not be where you expect. In that case, use expand (41.4) on the file, then pipe it to awk.

- JP, ML

27.16 Faking Case-Insensitive Searches |  | 27.18 Fast Searches and Spelling Checks with "look"